﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <div class="select-list">
                    <ul>
                        <li>
                            任务名称：<input id="jobName" name="JobName" type="text" />
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-info" onclick="showAutoJobLogForm()">
                <i class="fa fa-list"></i> 日志
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="gridTable"></table>
        </div>
    </div>
</div>


<script type="text/javascript">
    $(function () {
        var options = {
            id: "gridTable",
            url: "/SystemManage/AutoJob/GetPageListJson",
            createUrl: "/SystemManage/AutoJob/AutoJobForm",
            updateUrl: "/SystemManage/AutoJob/AutoJobForm",
            removeUrl: "/SystemManage/AutoJob/DeleteFormJson",
            exportUrl: "",
            modalName: "任务",
            sortName: "BaseCreateTime",
            sortOrder: "asc",
            columns: [
                { checkbox: true, visible: true },
                { field: 'id', title: 'id', visible: false },
                { field: 'jobGroupName', title: '任务组' },
                { field: 'jobName', title: '任务名称' },
                { field: 'cronExpression', title: 'Cron表达式' },
                {
                    field: 'jobStatus', title: '状态', formatter: function (value, row, index) {
                        if (row.jobStatus == "@StatusEnum.Yes.ParseToInt()") {
                            return '<span class="badge badge-primary">' + "运行中" + '</span>';
                        } else {
                            return '<span class="badge badge-danger">' + "停止" + '</span>';
                        }
                    }
                },
                { field: 'startTime', title: '开始时间' },

                { field: 'endTime', title: '结束时间' },
                { field: 'nextStartTime', title: '下次运行时间' },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (row.jobStatus == "@StatusEnum.Yes.ParseToInt()") {
                            actions.push('<a class="btn btn-primary btn-xs" href="#" onclick="ChangeJobStatus(\'' + row.id + '\',@StatusEnum.No.ParseToInt())"><i class="fa fa-pause-circle-o"></i>暂停</a> ');
                        } else {
                            actions.push('<a class="btn btn-primary btn-xs" href="#" onclick="ChangeJobStatus(\'' + row.id + '\',@StatusEnum.Yes.ParseToInt())"><i class="fa fa-play-circle-o"></i>执行</a> ');
                        }
                        return actions.join('');
                    }
                }
            ],
            onClickRow: function (row, element) {
                element[0].firstElementChild.firstElementChild.click();
            }
        };
        $.table.init(options);
    });
    //更改任务状态
    function ChangeJobStatus(id, jobStatus) {
        var postData = {};
        postData.Id = id;
        postData.JobStatus = jobStatus;
        ys.ajax({
            url: '@Url.Content("~/SystemManage/AutoJob/ChangeJobStatusJson")',
            type: "post",
            data: postData,
            success: function (obj) {
                if (obj.code == 1000) {
                    ys.msgSuccess(obj.Message);
                    $.form.reset();
                }
                else {
                    ys.msgError(obj.Message);
                }
            }
        });
    }

    function showAutoJobLogForm() {
        var url = '@Url.Content("~/SystemManage/AutoJobLog/AutoJobLogIndex")';
        createMenuItem(url, "任务日志", false);
    }
</script>
